package Features;

import java.util.ArrayList;
import core.Corpus;
import core.Document;


public class Feature {

	Boolean activo;
	public ArrayList<Feature> featureList;
	
	public Feature(){
		featureList = new ArrayList<Feature>();
	}
	
	public Feature(String features, Corpus corpus){
		featureList = new ArrayList<Feature>();
		featureList.add(new FeatureAbbreviation(features));
		featureList.add(new FeatureCapitalization(features));
		featureList.add(new FeatureExclamation(features));
		featureList.add(new FeatureLocations(features));
		featureList.add(new FeatureNumberOfTokens(features));
		featureList.add(new FeatureNumbers(features));
		featureList.add(new FeaturePersons(features));
		featureList.add(new FeatureQuestion(features));
		featureList.add(new FeatureSentencePosition(features));
		featureList.add(new FeatureTime(features));
		featureList.add(new FeatureWellKnownExpression(features));
		featureList.add(new FeatureUnigramas(features, corpus));
		featureList.add(new FeatureBigramas(features, corpus));
		featureList.add(new FeatureTrigramas(features, corpus));
		featureList.add(new FeatureVizinhos(features));
	}
	

	public void extract(Document doc) throws Exception{	
		if(activo==false) 
			return;
		for(int i=0; i<doc.sentenceList.length; i++){
			doc.sentenceList[i].featureVector+= " "+extractSentence(doc.sentenceList[i].frase);
		}
	}
	
	//Chama metodo da feature respectiva
	public String extractSentence(String sentence) throws Exception{ return "ERROR"; }
	
	public void extractFeatures(Corpus corpus) throws Exception{
		
		for(int i=0; i<corpus.listaDocumentos.length; i++){
			for (Feature it : featureList) {
				it.extract(corpus.listaDocumentos[i]);
			}
		}
		normalizaEspacosFeatureVector(corpus);
		
	}
	
	public void normalizaEspacosFeatureVector(Corpus corpus){
		
		for(int i=0; i<corpus.listaDocumentos.length; i++){
			for(int j=0; j<corpus.listaDocumentos[i].sentenceList.length; j++){
				corpus.listaDocumentos[i].sentenceList[j].featureVector = corpus.listaDocumentos[i].sentenceList[j].featureVector.trim().replaceAll("  ", " ");
			}
		}
	}
		
}
